VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsAsociado"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'Clase de asociado

Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1

Public Event DataChanged()

'Miembros de la Clase
Public codigo As String
Public codCliente As String
Public nro_registro As String
Public nombre As String
Public nit As String
Public contacto As String
Public email As String
Public direccion As String
Public ciudad As String
Public telefono As String
Public fecha_inscripcion As String
Public baja As String
Public fecha_baja As String
'fin declaracon miembros

'Constructor y Destructor
Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    orset.setCampos dbCampos(aso)
    orset.setTablas Array(aso)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub
' Generic Data management methods
'Public Sub consulta()
'    orset.consulta
'End Sub
Public Sub consultaDatos(codig As String)
    orset.consulta Array(aso_id & "=" & codig)
    orset.CierraRec
End Sub
Public Sub consultaXNumRegistro(numRegistro As String)
    orset.consulta Array(aso_nro_registro & "='" & numRegistro & "'")
    orset.CierraRec
End Sub
Public Sub consultaXClienteCod(optClienteCod As String)
    orset.consulta Array(aso_cli_id & "='" & optClienteCod & "'")
    orset.CierraRec
End Sub

Public Sub buscarGrid(Optional nit As String = "", Optional nombre As String = "", Optional asonro As String = "")
    Dim camposBuscar As String
    Dim condiciones As String
    camposBuscar = ""
    condiciones = ""
    Dim sql As ClsSQL
    Set sql = New ClsSQL
    sql.reset
    'solo asociados
    camposBuscar = camposBuscar + "CASE WHEN "
        If asonro <> "" Then
            camposBuscar = camposBuscar + aso_nro_registro + " LIKE '" + asonro + "%' AND "
        End If
        If nit <> "" Then
            camposBuscar = camposBuscar + cli_nit + " LIKE '" + nit + "%' AND "
        End If
        If nombre <> "" Then
            camposBuscar = camposBuscar + cli_nombre + " LIKE '" + nombre + "%' AND "
        End If
    camposBuscar = Strings.Left(camposBuscar, Strings.Len(camposBuscar) - 4) & " THEN 1 "
        If asonro <> "" Then
            camposBuscar = camposBuscar + "WHEN " & aso_nro_registro & " LIKE '" + asonro + "%' THEN 2 "
            condiciones = condiciones + "aso_nro_registro LIKE '" + asonro + "%' OR "
        End If
        If nit <> "" Then
            camposBuscar = camposBuscar + "WHEN " & cli_nit & " LIKE '" + nit + "%' THEN 3 "
            condiciones = condiciones + "cli_nit LIKE '" + cli_nit + "%' OR "
        End If
        If nombre <> "" Then
            camposBuscar = camposBuscar & "WHEN " & cli_nombre & " LIKE '" + nombre + "%' THEN 4 "
            condiciones = condiciones & cli_nombre & " LIKE '" + cli_nombre + "%' OR "
        End If
    condiciones = Strings.Left(condiciones, Strings.Len(condiciones) - 3)
    camposBuscar = camposBuscar + "END AS orden"
    sql.setCampos concatenaVectores(dbCampos(aso), Array(camposBuscar))
    sql.setTablas Array(aso, cli)
    sql.setCondiciones Array(aso_cli_id & "=" & cli_id, condiciones)
    sql.setOrden Array("orden", cli_nombre)
    
End Sub
Public Sub Nuevo(newCliId As String, newNroRegistro As String, newNombre As String, newNit As String, newContacto As String, newEmail As String, newDireccion As String, newCiudad As String, newTelefono As String, newFechaInscripcion As String, newBaja As String, newFechaBaja As String)
    orset.sInsert Array("", newCliId, newNroRegistro, newNombre, newNit, newContacto, newEmail, newDireccion, newCiudad, newTelefono, newFechaInscripcion, newBaja, newFechaBaja)
End Sub
Public Sub Modificar(codig As String, newCliId As String, newNroRegistro As String, newNombre As String, newNit As String, newContacto As String, newEmail As String, newDireccion As String, newCiudad As String, newTelefono As String, newFechaInscripcion As String, newBaja As String, newFechaBaja As String)
    orset.sUpdate Array(codig, newCliId, newNroRegistro, newNombre, newNit, newContacto, newEmail, newDireccion, newCiudad, newTelefono, newFechaInscripcion, newBaja, newFechaBaja)
End Sub
Public Sub Borrar(codig As String)
    orset.sDelete codig
End Sub

Private Sub Reload_members()
    With orset
        codigo = .getDato(aso_id)
        codCliente = .getDato(aso_cli_id)
        nro_registro = .getDato(aso_nro_registro)
        nit = .getDato(aso_nit)
        nombre = .getDato(aso_nombre)
        contacto = .getDato(aso_contacto)
        email = .getDato(aso_email)
        direccion = .getDato(aso_direccion)
        telefono = .getDato(aso_telefono)
        fecha_inscripcion = .getDato(aso_fecha_inscripcion)
        baja = .getDato(aso_baja)
        fecha_baja = .getDato(aso_fecha_baja)
    End With
    RaiseEvent DataChanged
End Sub
Private Sub orset_DataChanged()
    Reload_members
End Sub
